package com.ghy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ghy.entity.Ident;
import com.ghy.service.IdentService;
import com.ghy.utils.Message;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;

@Api( tags ="共用二维码功能接口")
@CrossOrigin
@RestController
@RequestMapping(value = "/ident")
public class IdentController {
    @Resource
    private IdentService identService;


    @ApiOperation(value = "添加巡检点", notes = "picture  图片，video是视频，目前都是单张上传")
    @RequestMapping( method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public Message saveIdent(Ident ident,@RequestParam(value = "picture", required = false) MultipartFile picture,@RequestParam(value = "video", required = false) MultipartFile video){
        identService.saveIdent(ident,picture,video);
        return Message.ok(  "新增成功");
    }

    @DeleteMapping(value = "{id}"  , produces = MediaType.APPLICATION_JSON_VALUE)
    public Message deleteIdent(@PathVariable Long id){
         identService.deleteIdent(id);

        return Message.ok("删除成功");
    }


    @RequestMapping( method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
    public  Message updateIdent(Ident ident, @RequestParam(value = "picture", required = false)MultipartFile picture, @RequestParam(value = "video", required = false)MultipartFile video){
        boolean i = identService.updateIdent(ident,picture,video);
        return Message.ok("修改成功");
    }


    @ApiOperation(value = "根据ID查找")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "url", value = "需要生成二维码的路径", required = false  )
    })
    @GetMapping(  value = "{id}" , produces = MediaType.APPLICATION_JSON_VALUE)
    public Message findById(@PathVariable Long id, @RequestParam(value = "url", required = false) String url, HttpServletResponse response) throws Exception {

        return Message.ok(identService.findById(id,url,response));
    }

    @ApiOperation(value = "分页查询所有数据，可以模糊匹配 , 需要将系统类别带上 是String类型  ")
    @GetMapping(    produces = MediaType.APPLICATION_JSON_VALUE)
    public Message listIdent(@ApiParam Page page,Ident ident){

        return Message.ok (identService.listIdent(page,ident));
    }

    @ApiOperation(value = "生成下拉选 ")
    @GetMapping(value = "/find", produces = MediaType.APPLICATION_JSON_VALUE)
    public Message findSelect (){

        return Message.ok (identService.findSelect());
    }
    @ApiOperation(value = "根据类型进行修改, 修改时全把对应类型全部修改，修改前字段 字段名sysType  ")
    @RequestMapping( method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE,value = "sysType")
    public  Message updateSysType(String frontType,String sysType){
        identService.updateSysType(frontType,sysType);
        return Message.ok("修改成功");
    }
    @ApiOperation(value = "根据类型进行批量删除,传递字段sysType")
    @RequestMapping( method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE,value = "sysType")
    public  Message deleteType(String sysType){
        identService.deleteType(sysType);
        return Message.ok("修改成功");
    }

}
